clear
set more off

rename chinaversion1exchangerateus1 ex_cn
rename indiaexchangerateus1 ex_ind
rename indonesiaexchangerateus1 ex_indo
rename malaysiaexchangerateus1 ex_my
rename mexicoexchangerateus1 ex_mx
rename southafricaexchangerateus1 ex_sa
rename turkeyexchangerateus1 ex_tk
rename chinaversion1purchasingpowerpari ppp_cn
rename indiapurchasingpowerparityovergd ppp_ind
rename indonesiapurchasingpowerparityov ppp_indo
rename malaysiapurchasingpowerparityove ppp_my
rename mexicopurchasingpowerparityoverg ppp_mx
rename southafricapurchasingpowerparity ppp_sa
rename turkeypurchasingpowerparityoverg ppp_tk
rename chinaversion1opennessinconstantp op_cn
rename indiaopennessinconstantpricesin2 op_ind
rename indonesiaopennessinconstantprice op_indo
rename malaysiaopennessinconstantprices op_my
rename mexicoopennessinconstantpricesin op_mx
rename southafricaopennessinconstantpri op_sa
rename turkeyopennessinconstantpricesin op_tk
rename chinaversion1growthrateofrealgdp gdp_cn
rename indiagrowthrateofrealgdpchainper gdp_ind
rename indonesiagrowthrateofrealgdpchai gdp_indo
rename malaysiagrowthrateofrealgdpchain gdp_my
rename mexicogrowthrateofrealgdpchainpe gdp_mx
rename southafricagrowthrateofrealgdpch gdp_sa
rename turkeygrowthrateofrealgdpchainpe gdp_tk


//keep ex_ind ppp_ind op_ind year gdp_ind

reshape long ex ppp op gdp, i(year) j(country) s
encode country, gen(cid)
xtset cid year
gen rex=ex/ppp
gen lnop=ln(op)
gen gdp_per=gdp/100

xtline rex
xtline gdp_per
xtline lnop

xtline rex, overlay title(Real exchange rates across countries 1980-2007)
xtline gdp_per, overlay title(Real GDP growth rates across countries 1980-2007)
xtline lnop, overlay title(Openness level across countries 1980-2007)
xtreg rex gdp_per lnop, fe

//ssc install xttest3
xttest3

bysort cid: egen rex_mean=mean(rex)
twoway scatter rex cid, msymbol(circle_hollow) || connected rex_mean cid, msymbol(diamond) || , xlabel(1"China"2"India"3"Indonesia"4"Mexico"5"Malaysia"6"South_Africa"7"Turkey") title(Heterogeneity across countries)
bysort year: egen rex_mean1=mean(rex) 
twoway scatter rex year, msymbol(circle_hollow) || connected rex_mean1 year, msymbol(diamond) || , xlabel(1980(1)2007) title(Heterogeneity across years)

/* to install xtserial package in STATA
 net from http://www.stata-journal.com/software/sj3-2/
.net describe st0039
 net install st0039
*/
xtserial rex gdp_per lnop, output


//VAR with India Data//
clear

//input data//
keep year ex_ind ppp_ind op_ind gdp_ind

tsset year
gen rex=ex_ind/ppp_ind
gen lnop=ln(op_ind)
gen gdp_per=gdp_ind/100
varsoc rex lnop gdp_per
var rex lnop gdp_per, lags(1), if year<=2000
vargranger
varlmar
varnorm
fcast compute F_, step(7)
fcast graph F_rex F_lnop F_gdp_per, observed lpattern(dash)
var rex lnop gdp_per, lags(1)
irf create results, set(myirfs, replace)
irf graph oirf, response(rex)
irf table oirf, response(rex)
irf table fevd, response(rex)
irf graph fevd
